package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Interfaces.Interface;
import edu.pku.sei.modeler.model.uml.Interfaces.InterfaceRealization;

public class UMLInterfaceRealizationDeleteCommand extends
		UMLRealizationDeleteCommand {

	public UMLInterfaceRealizationDeleteCommand(
			MetaModelElement connectionModel, MetaModelElement sourceModel,
			MetaModelElement targetModel) {
		super(connectionModel, sourceModel, targetModel);
	}

	@Override
	public boolean canExecute() {
		if (super.canExecute() && this.targetModel instanceof Interface) {
			return true;
		} else {
			return false;
		}

	}

	@Override
	public void execute() {
		InterfaceRealization interfaceRealization = (InterfaceRealization) this.connectionModel;
		interfaceRealization.getContract().remove(targetModel);
		super.execute();
	}

	@Override
	public void undo() {
		super.undo();
		InterfaceRealization interfaceRealization = (InterfaceRealization) this.connectionModel;
		interfaceRealization.getContract().add(targetModel);
	}

}
